package com.example.shop.mapper;

import com.example.shop.entity.GoodsImage;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2025/9/2 21:41
 **/
@Mapper
public interface GoodsImageMapper {
    @Insert("""
INSERT INTO mi_goods_image (goods_id, type, file_id, order_num, create_time, update_time, 
operator_id, is_delete) VALUES (#{goodsId}, #{type}, #{fileId}, #{orderNum}, now(), now(), null, 0);
""")
    void saveGoodsImage(GoodsImage goodsImage);

    @Insert("""
<script>
INSERT INTO mi_goods_image (goods_id, type, file_id, order_num, create_time, update_time, operator_id, is_delete) 
VALUES 
<foreach collection='goodsImages' item='image' separator=','>
    (#{image.goodsId}, #{image.type}, #{image.fileId}, #{image.orderNum}, now(), now(), null, 0)
</foreach>
</script>
""")
    void batchInsertGoodsImages(@Param("goodsImages") List<GoodsImage> goodsImages);

    @Select("""
select file_id from mi_goods_image where goods_id = #{goodsId} and type = #{type}
""")
    List<String> queryGoodsImage(@Param("goodsId") String goodsId,
                                 @Param("type") String type);

    @Select("""
select file_id from mi_goods_image where goods_id = 'shop_home_default'
""")
    String queryGoodsImageDefault();
}
